<?php require('connections/con_gl.php'); ?>

<?php

cekAkses($_SESSION[akses],"PJ-3");

$currentPage = $_SERVER["PHP_SELF"];



$maxRows_data = 8;

$pageNum_data = 0;

if (isset($_GET['pageNum_data'])) {

  $pageNum_data = $_GET['pageNum_data'];

}

$startRow_data = $pageNum_data * $maxRows_data;

$cr_txt = str_replace("+"," ",$_REQUEST[cr_txt]);

mysql_select_db($database_con_gl, $con_gl);

$query_data = "SELECT gl_rtrans.tgl, gl_trans.no_ref, gl_trans.transaksi, gl_trans.total, gl_trans.tglretur, gl_gudang.gudang, gl_barang.barang, gl_trans.barang as brg_id, gl_satuan.satuan, gl_trans.jumlah FROM gl_trans, gl_rtrans, gl_gudang, gl_barang, gl_satuan WHERE gl_rtrans.no_ref=gl_trans.no_ref AND gl_gudang.id=gl_rtrans.gudang AND gl_barang.id=gl_trans.barang AND gl_satuan.id=gl_trans.satuan AND gl_trans.retur=2";

if(!strstr($_SESSION[akses],'A-1-4')) {

	$query_data .= " AND gl_rtrans.gudang='$_SESSION[lokasi]'";

}

if($_GET[cr_agen]<>'ALL' AND $_GET[cr_agen]<>'') { 

$query_data .=" AND gl_rtrans.kontak='$_GET[cr_agen]'";

}

if($_GET[cr_barang]<>'ALL' AND $_GET[cr_barang]<>'') { 

$query_data .=" AND gl_trans.barang='$_GET[cr_barang]'";

}

if($_GET[gudang]<>'ALL' AND $_GET[gudang]<>'') { 

$query_data .=" AND gl_rtrans.gudang='$_GET[gudang]'";

}

if($_GET[mulai]<>'' AND $_GET[sampai]<>'') { 

$query_data .=" AND gl_rtrans.tgl between '$_GET[mulai]' AND '$_GET[sampai]'";

}

$query_data .=" ORDER BY gl_trans.no_ref desc";

$query_limit_data = sprintf("%s LIMIT %d, %d", $query_data, $startRow_data, $maxRows_data);

$data = mysql_query($query_limit_data, $con_gl) or die(mysql_error());

$row_data = mysql_fetch_assoc($data);



if (isset($_GET['totalRows_data'])) {

  $totalRows_data = $_GET['totalRows_data'];

} else {

  $all_data = mysql_query($query_data);

  $totalRows_data = mysql_num_rows($all_data);

}

$totalPages_data = ceil($totalRows_data/$maxRows_data)-1;



$queryString_data = "";

if (!empty($_SERVER['QUERY_STRING'])) {

  $params = explode("&", $_SERVER['QUERY_STRING']);

  $newParams = array();

  foreach ($params as $param) {

    if (stristr($param, "pageNum_data") == false && 

        stristr($param, "totalRows_data") == false) {

      array_push($newParams, $param);

    }

  }

  if (count($newParams) != 0) {

    $queryString_data = "&" . htmlentities(implode("&", $newParams));

  }

}

$queryString_data = sprintf("&totalRows_data=%d%s", $totalRows_data, $queryString_data);

include('include/widget_export_trans.php');

?>

<link href="css/ui.datepicker.css" type="text/css" rel="stylesheet" />

<script type="text/javascript" src="js/ui.datepicker.js"></script>

<script type="text/javascript">

<!--

$(function()

      {

        $('.calendar').datepicker({

            appendText : "",

            dateFormat : 'yy/mm/dd'

          });

      });

</script>

<script type="text/javascript">

$(document).ready(function(){

$(".flipsearch").click(function(){

	$("form.tanggalsearch").hide() 

    $(".objsearch").slideToggle("fast");

  });

});



$(document).ready(function(){

$(".fliptanggal").click(function(){

	$("form.objsearch").hide();

    $(".tanggalsearch").slideToggle("fast");

  });

});

</script>

<h1>Retur Penjualan</h1>

<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="datatable"> 

  <tr class="hide">

    <td><?php if(strstr($_SESSION['akses'],"PJ-3-1")) { ?><a href="index.php?component=returpenjualan&amp;task=add"><img src="images/add_new.png" border="0" /></a><?php } ?></td>

    <td>&nbsp;</td>

    <td colspan="5" align="right"><?php

	mysql_select_db($database_con_gl, $con_gl);

$query_cr_gud = "SELECT id, gudang FROM gl_gudang";

if(!strstr($_SESSION[akses],'A-1-4')) {

	$query_cr_gud .= " where id='$_SESSION[lokasi]' ";

}

$query_cr_gud .= " ORDER BY gudang ASC";

$cr_gud = mysql_query($query_cr_gud, $con_gl) or die(mysql_error());

$row_cr_gud = mysql_fetch_assoc($cr_gud);

$totalRows_cr_gud = mysql_num_rows($cr_gud);



mysql_select_db($database_con_gl, $con_gl);

$query_cr_agen = "SELECT id, nama FROM gl_kontak where type='Agen' ORDER BY nama ASC";

$cr_agen = mysql_query($query_cr_agen, $con_gl) or die(mysql_error());

$row_cr_agen = mysql_fetch_assoc($cr_agen);

$totalRows_cr_agen = mysql_num_rows($cr_agen);



mysql_select_db($database_con_gl, $con_gl);

$query_kelom = "SELECT id, kelompok FROM gl_kelompok where jual=1 ORDER BY kelompok ASC";

$kelom = mysql_query($query_kelom, $con_gl) or die(mysql_error());

$row_kelom = mysql_fetch_assoc($kelom);

$totalRows_kelom = mysql_num_rows($kelom);

?>

      <form id="search" name="search" method="post" action="" class="objsearch">

        <br />

        <label>

          <select name="cr_gudang">

          <option value="ALL">Lokasi Kantor</option>

          <?php

do {  

?>

          <option value="<?php echo $row_cr_gud['id']?>"><?php echo $row_cr_gud['gudang']?></option>

          <?php

} while ($row_cr_gud = mysql_fetch_assoc($cr_gud));

  $rows = mysql_num_rows($cr_gud);

  if($rows > 0) {

      mysql_data_seek($cr_gud, 0);

	  $row_cr_gud = mysql_fetch_assoc($cr_gud);

  }

?>

        </select>

        </label>

        <label>

        <select name="cr_agen" id="cr_agen">

          <option value="ALL">Agen</option>

          <?php

do {  

?>

          <option value="<?php echo $row_cr_agen['id']?>"><?php echo $row_cr_agen['nama']?></option>

          <?php

} while ($row_cr_agen = mysql_fetch_assoc($cr_agen));

  $rows = mysql_num_rows($cr_agen);

  if($rows > 0) {

      mysql_data_seek($cr_agen, 0);

	  $row_cr_agen = mysql_fetch_assoc($cr_agen);

  }

?>

        </select>

        </label>

        <label>

        <select name="cr_barang" id="cr_barang">

		<option value="ALL">Barang</option>

          <?php

do {  

mysql_select_db($database_con_gl, $con_gl);

$query_getpro = "SELECT id, barang, keterangan FROM gl_barang where kelompok='$row_kelom[id]' order by barang";

$getpro = mysql_query($query_getpro, $con_gl) or die(mysql_error());

$row_getpro = mysql_fetch_assoc($getpro);

$totalRows_getpro = mysql_num_rows($getpro);

?>

          <?php

 if($totalRows_getpro  > 0) { ?>

          <option value="" style="background:#DDDDDD;font-weight:bold;"><?php echo $row_kelom['kelompok']?></option>

          <?php do { ?>

          <option value="<?php echo $row_getpro['id']; ?>" title="<?php echo $row_getpro['keterangan']; ?>">-<?php echo $row_getpro['barang']; ?></option>

          <?php }  while ($row_getpro = mysql_fetch_assoc($getpro)); ?>

          <?php } ?>

          <?php

} while ($row_kelom = mysql_fetch_assoc($kelom));

  $rows = mysql_num_rows($kelom);

  if($rows > 0) {

      mysql_data_seek($kelom, 0);

	  $row_kelom = mysql_fetch_assoc($kelom);

  }

?>

        </select>

        </label>

        <label>

        <input name="mulai" type="text" id="mulai" value="<?php echo $_GET[mulai];?>" size="15" maxlength="15" class="calendar"/>

        </label>

        s/d

  <label>

  <input name="sampai" type="text" id="sampai" value="<?php echo $_GET[sampai];?>" size="15" maxlength="15" class="calendar"/>

  </label>

  <label>

        <input name="Search" type="submit" id="Search" value="Search" />

        </label>

      </form>

    <?php

	if(isset($_POST['Search'])) {

		echo "<script>window.location=\"index.php?component=returpenjualan&mulai=".$_POST[mulai]."&sampai=".$_POST[sampai]."&cr_agen=".$_POST[cr_agen]."&cr_barang=".$_POST[cr_barang]."&gudang=".$_POST[cr_gudang]."\";</script>";

	}

	?></td>

  </tr>

  <tr>

    <th width="10%"><strong>Tanggal</strong></th>

    <th width="12%"><strong>No Referensi </strong></th>

    <th width="22%"><strong>Lokasi Kantor</strong></th>

    <th align="left"><strong>Barang</strong></th>

    <th width="12%"><strong>Jumlah</strong></th>

    <th width="12%" align="center"><strong>Total</strong></th>

    <th width="76" align="center" class="hide"><strong>Aksi</strong></th>

  </tr>

  <?php if($totalRows_data > 0) { ?>

  <?php do { ?>

  <?php

mysql_select_db($database_con_gl, $con_gl);

$query_hitung = "SELECT sum(gl_trans.total) FROM gl_trans WHERE gl_trans.no_ref='$row_data[no_ref]' AND pos='K'";

$hitung = mysql_query($query_hitung, $con_gl) or die(mysql_error());

$row_hitung = mysql_fetch_assoc($hitung);

$totalRows_hitung = mysql_num_rows($hitung);

  ?>

    <tr valign="top" bgcolor="#FFFFFF">

      <td align="center"  ><?php tanggal($row_data['tgl'],"tampilkan"); ?></td>

      <td align="center" ><a href="include/jurnalvoucher_transaksi.php?referensi=<?php echo $row_data['no_ref'];?>" onclick="NewWindow(this.href,'name','1050','300','yes');return false" title="Jurnal Voucher"><?php echo $row_data['no_ref']; ?></a></td>

      <td width="130" ><?php echo $row_data['gudang']; ?></td>

      <td width="274" align="left" ><?php echo $row_data['barang']; ?></td>

      <td width="85" align="left" ><?php echo $row_data['jumlah']; ?> <?php echo $row_data['satuan']; ?></td>

      <td width="125" align="right" bgcolor="#FFFFFF" ><?php echo number_format($row_data['total'],0,',','.').",-"; ?></td>

      <td align="center" bgcolor="#FFFFFF" class="hide"><?php if(strstr($_SESSION['akses'],"PJ-3-2")) { ?><a href="index.php?component=returpenjualan&amp;task=edit&amp;noreferensi=<?php echo $row_data[no_ref];?>"><img src="images/edit_.png" border="0" /></a><?php } ?> <?php if(strstr($_SESSION['akses'],"PJ-3-3")) { ?><a href="index.php?component=returpenjualan&amp;task=delete&amp;noreferensi=<?php echo $row_data[no_ref];?>" class="ask"><img src="images/delete_.png" border="0" /></a><?php } ?></td>

    </tr>

    <?php } while ($row_data = mysql_fetch_assoc($data)); ?>

	<?php if($totalRows_data > $maxRows_data) { ?>

    <tr class="hide">

      <td colspan="7"  ><table border="0" align="left">

          <tr>

            <td width="23%" align="center"><?php if ($pageNum_data > 0) { // Show if not first page ?>

                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, 0, $queryString_data); ?>"><img src="First.gif" border=0></a>

                <?php } // Show if not first page ?>            </td>

            <td width="31%" align="center"><?php if ($pageNum_data > 0) { // Show if not first page ?>

                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, max(0, $pageNum_data - 1), $queryString_data); ?>"><img src="Previous.gif" border=0></a>

                <?php } // Show if not first page ?>            </td>

            <td width="23%" align="center"><?php if ($pageNum_data < $totalPages_data) { // Show if not last page ?>

                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, min($totalPages_data, $pageNum_data + 1), $queryString_data); ?>"><img src="Next.gif" border=0></a>

                <?php } // Show if not last page ?>            </td>

            <td width="23%" align="center"><?php if ($pageNum_data < $totalPages_data) { // Show if not last page ?>

                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, $totalPages_data, $queryString_data); ?>"><img src="Last.gif" border=0></a>

                <?php } // Show if not last page ?>            </td>

          </tr>

        </table></td>

    </tr>

	<?php } ?>

   <?php }else{ ?>

  <tr bgcolor="#FFFFFF">

    <td colspan="7"  >Data tidak ada !!! </td>

  </tr>

  <?php } ?>

  <tr bgcolor="#FFFFFF" class="hide">

     <td colspan="7"  ><?php if(strstr($_SESSION['akses'],"PJ-3-1")) { ?>

       <a href="index.php?component=returpenjualan&amp;task=add"><img src="images/add_new.png" border="0" /></a>

     <?php } ?></td>

   </tr>

</table>

